// JavaScript Document

//JS操作cookies方法!

//写cookies
function setCookie(c_name, value, expiredays)
{
	//alert("set name:" + c_name);
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
	//alert("cookie:" + document.cookie);
} 
/**
 * 默认30分钟
 * @param c_name
 * @param value
 */
function setCookieDefaultTime(c_name, value){
	setCookieTime(c_name, value, 15);
}
function setCookieTime(c_name, value, time){
	var date=new Date(); 
	date.setTime(date.getTime()+ time*60*1000); //设置date为当前时间+30分
	document.cookie=c_name+ "=" + escape(value) + ((time==null) ? "" : ";expires=" + date.toGMTString());
}
function setCookieDefault(c_name, value)
{
	setCookie(c_name, value, 30);
}

 
//读取cookies
function getCookie(name)
{
	/*var cookie = document.cookie;

	var items = cookie.split(';');
	
	for (var i=0; i<items.length; i++)
	{
		var _item = items[i].split('=');
		
		alert("-" + name + "--" + _item[0] + "--");
		
		if(_item[0].trim() == name.trim())
		{
			alert(1);
			return _item[1];
		}
	}
	
	return null;*/

    var arr,reg =  new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
 	{
        return (arr[2]);
	}
    else
	{
		return null;
	}
}

//删除cookies
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
  
    document.cookie = name + "=;expires="+exp.toGMTString();
   // alert("del coo:" + document.cookie);
}

function clearCookies()
{
	var cookies = document.cookie.split(";");  
	
    for (var i = 0; i < cookies.length; i++) 
	{  
        var cookie = cookies[i];  
        
        var name = cookie.split("=")[0]; 
        //alert("del name:" + name);
		delCookie(name);  
    }  
}

function getCookies()
{
	return document.cookie;  
}